package com.xc.h05.service.lishenao.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xc.h05.entity.Article;
import com.xc.h05.entity.Consult;
import com.xc.h05.mapper.ArticleMapper;
import com.xc.h05.mapper.ConsultMapper;
import com.xc.h05.service.lishenao.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private ArticleMapper articleMapper;
    @Autowired
    private ConsultMapper consultMapper;
    @Override
    public int deleteByPrimaryKey(Long id) {
        return articleMapper.deleteByPrimaryKey(id);
    }


    @Override
    public int insertSelective(Article record) {
        record.setCreatetime(new Date());
        return articleMapper.insert(record);
    }

    @Override
    public Article selectByPrimaryKey(Long id) {
        return articleMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Article record) {
        record.setCreatetime(new Date());
        return articleMapper.updateByPrimaryKeySelective(record);
    }


    @Override
    public PageInfo<Article> findAll(Integer pageNum, Integer pageSize, Article article) {
        PageHelper.startPage(pageNum,pageSize);
        List<Article> list = articleMapper.findAll(article);
        PageInfo<Article> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<Consult> findAffConsult() {
        return consultMapper.findAll();
    }

    @Override
    public Article findById(Long id) {
        return articleMapper.selectByPrimaryKey(id);
    }
}
